<?php
session_start();

    //error_reporting(0);// turn off errors on release
    $settings = parse_ini_file('troll.ini',true);
    require 'includes/dbconnect.php';
    require 'includes/functions.php';

    $_SESSION['msg'] = '';

    /* only way here is form playerselect */
    if(strpos($_SERVER['HTTP_REFERER'],'playerselect.php') ||
    	strpos($_SERVER['HTTP_REFERER'],'create.php'))    	
    { 

    	/* CREATING CHARACTER */
    	if(isset($_POST['create']))
    	{
    		$c = $_POST;
    		$name = strtoupper($c['name']);

    		/* just need to check against name match */
    		$sql = "SELECT `name` FROM characters WHERE `name` = '$name' LIMIT 1";
    		$query = $db->query($sql);
    		$query->fetch();
			
			if( $query->rowCount() > 0 )
			{
				$_SESSION['msg'] = '<p><font color="red">'.$c['name'].' is not available</font></p>';


			}/* name exists */
			else
			{
				/* all good, add it */
	    		if(createCharacter($_POST))
	    		{
	    			header('location:playerselect.php');
	    			die();
	    		}
	    		else
	    		{
	    			$_SESSION['msg'] = "<p class='error_msg'>Could not add character.</p>";
	    		}
    		}// else add character
    	}// post creat?

 ?>
 		<html>
		<head>
    		<link rel="stylesheet" type="text/css" href="scripts/troll.css"/>
    		<title>TROLL: Characater Creation</title>
		</head>
		<body>
    		<center>
    		<div class="console">        
        		<table width="800" clas="console">
            		<tr>
                		<td>                
                    		<center>
	                    		<img src='images/troll.bmp'/><br/>
								
								<h1>CHARACTER creation</h1>
								
								<form method="post" action="create.php">
									<input type="text" name="name" placeholder="Character Name" autofocus /><br/>
									<p>
										Class: 
										<input type="radio" name="class" value="1" checked="checked" />Warrior 
										<input type="radio" name="class" value="2"/>Mage 
										<input type="radio" name="class" value="3"/>Rogue 
									</p>

									<p>
										Gender 
										<input type="radio" name="sex" value="0" checked="checked" />Male 
										<input type="radio" name="sex" value="1"/>Female 
									</p>
									<p><?php 
										if($_SESSION['msg'] > '' ) echo $_SESSION['msg'];
									?></p>	
									<p><input type="submit" value="Create" name="create"/></p>
															
								</form>
							</center>	
						</td>
					</tr>	
				</table>
			</div>	
			</center>
		</body>	
		</html>	


<?php
    }/* incomeing from playerselect */
    else
    {
    	header('location:index.php');
    	die();
    }

?>